package coffeenc.mall.admin.mapper;

import coffeenc.mall.admin.entity.UmsResource;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 后台用户与角色关系Mapper
 * Created by coffeenc on 2020/9/19
 */
@Mapper
public interface UmsResourceMapper {
    /**
     * 获取用户的所有可访问资源
     */
    @Select({"SELECT "+
            "ur.id id,"+
            "ur.create_time createTime,"+
            "ur.name name,"+
            "ur.url url,"+
            "ur.description description,"+
            "ur.category_id categoryId "+
            "FROM ums_admin_role_relation arr "+
            "INNER JOIN ums_role r ON r.id = arr.role_id AND arr.admin_id = #{adminId} "+
            "INNER JOIN ums_role_resource_relation urrr ON r.id = urrr.role_id "+
            "INNER JOIN ums_resource ur ON urrr.resource_id = ur.id "})
    List<UmsResource> getResourceListByAdminId(Long adminId);
}